
package com.cn.项目.飞机预约管理系统.Logining;

import com.cn.项目.utils.JdbcUtils;

import java.awt.*;
import java.awt.event.*;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import javax.swing.*;


public class Register extends JFrame {
    public Register() {
        initComponents();
    }

    //注册响应
    private void button2ActionPerformed(ActionEvent e) {
        // TODO add your code here
        Connection conn = null;
        PreparedStatement st = null;
        String id = textField1.getText();
        String password = textField2.getText();
        String p2 = textField4.getText();
        if(password.equals(p2)){
            try {
                conn = JdbcUtils.getConnection();
                String sql = "INSERT INTO `manager`(`id`,`password`)VALUES(?,?)";
                st = conn.prepareStatement(sql);
                st.setString(1, id);
                st.setString(2, password);
                int i = st.executeUpdate();

                if(i>0){
                    //注册成功提示
                    new Successprompt();
                    this.dispose();
                }
            } catch (SQLException e1) {
                e1.printStackTrace();
            }finally {
                JdbcUtils.release(conn, st,null );
            }

        }else {

            //添加错误提示
            new Errorprompt();
            textField1.setText(" ");
            textField2.setText(" ");
            textField4.setText(" ");

        }
        }



    private void initComponents() {
        // JFormDesigner - Component initialization - DO NOT MODIFY  //GEN-BEGIN:initComponents
        label1 = new JLabel();
        label2 = new JLabel();
        label3 = new JLabel();
        textField1 = new JTextField();
        textField2 = new JTextField();
        textField4 = new JTextField();
        button2 = new JButton();
        label4 = new JLabel();

        //======== this ========
        setVisible(true);
        Container contentPane = getContentPane();
        contentPane.setLayout(null);

        //---- label1 ----
        label1.setText("请您注册");
        label1.setFont(label1.getFont().deriveFont(label1.getFont().getSize() + 10f));
        label1.setForeground(new Color(204, 0, 0));
        contentPane.add(label1);
        label1.setBounds(130, 20, 160, 35);

        //---- label2 ----
        label2.setText("账号");
        label2.setFont(label2.getFont().deriveFont(label2.getFont().getSize() + 6f));
        contentPane.add(label2);
        label2.setBounds(30, 80, 85, 30);

        //---- label3 ----
        label3.setText("密码：");
        label3.setFont(label3.getFont().deriveFont(label3.getFont().getSize() + 6f));
        contentPane.add(label3);
        label3.setBounds(30, 150, 65, 40);

        //---- textField1 ----
        textField1.setText("请输入你要注册的账号");
        contentPane.add(textField1);
        textField1.setBounds(150, 80, 180, 35);

        //---- textField2 ----
        textField2.setText("请输入你的密码");
        contentPane.add(textField2);
        textField2.setBounds(150, 160, 180, 35);

        //---- textField4 ----
        textField4.setText("请确认密码");
        contentPane.add(textField4);
        textField4.setBounds(155, 225, 185, 35);

        //---- button2 ----
        button2.setText("注册");
        button2.setFont(button2.getFont().deriveFont(button2.getFont().getSize() + 6f));
        button2.setForeground(new Color(0, 255, 51));
        button2.addActionListener(e -> button2ActionPerformed(e));
        contentPane.add(button2);
        button2.setBounds(155, 295, button2.getPreferredSize().width, 40);

        //---- label4 ----
        label4.setText("确认密码：");
        label4.setFont(label4.getFont().deriveFont(label4.getFont().getSize() + 6f));
        contentPane.add(label4);
        label4.setBounds(30, 230, 115, 35);

        contentPane.setPreferredSize(new Dimension(400, 395));
        pack();
        setLocationRelativeTo(getOwner());
        // JFormDesigner - End of component initialization  //GEN-END:initComponents
    }

    // JFormDesigner - Variables declaration - DO NOT MODIFY  //GEN-BEGIN:variables
    private JLabel label1;
    private JLabel label2;
    private JLabel label3;
    private JTextField textField1;
    private JTextField textField2;
    private JTextField textField4;
    private JButton button2;
    private JLabel label4;
    // JFormDesigner - End of variables declaration  //GEN-END:variables
}
